<?php
require_once(OC::$SERVERROOT . "/apps/reports/lib/helper.php");
require_once(OC::$SERVERROOT . "/apps/reports/lib/reports.php");

if (!PFactory::isMasterUser()) {
   echo '您无权访问该资源';
   exit();
}

$start = JRequest::getString('start', '');
$end = JRequest::getString('end', '');
$xtypes = array('resume', 'event', 'offer', 'entry');

$model = new PReportsModelReports();
$summary = $model->getJobSummary();

if ($summary === false) {
   jexit('<div class="yahei large noreportsdata">' . ($model->getError() ? $model->getError() : '系统错误') . '</div>');
}

list($jobList, $pagination) = $model->getJobList();
$tmpl = new OCP\Template('reports', 'part.reports.joblist', '');
$tmpl->assign('jobList', $jobList);
$tmpl->assign('pagination', $pagination);
?>

<div class="rep_resumefrom" style="margin-top:20px;" id="anchor_trend">
   <h5><b>趋势情况</b></h5>
   <div class="rep_datashow">
      <span><i class="c4"></i> 发布中职位<b><?=$summary['date']['totaljob']?></b></span>
      <em></em>
      <span><i class="c2"></i> 新增职位<b><?=$summary['date']['newjob']?></b></span>
      <!--
      <em></em>
      <span><i class="c3"></i> 已关闭职位<b>33</b></span>
      -->
   </div>

   <div class="putcanvas">
      <div id="dateLine" style="height:215px; width:100%;"></div>
   </div>
</div>

<div class="rep_resumefrom" id="anchor_liucheng">
   <h5><b>流程设置情况</b></h5>

   <div class="clearfix">
      <div id="jobSummaryBar" class="pull-left" style="height:205px; width:60%"></div>

      <div class="rep_detailtable pull-right" style="width:35%; margin-top:10px;">
         <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
               <th width="34%">流程设置</th>
               <th width="33%">职位数</th>
               <th width="33%">比例</th>
            </tr>
            <tr>
               <td class="medium">已设匹配条件</td>
               <td><?=$summary['details']['interview_setup']['count']?></td>
               <td><?=$summary['details']['interview_setup']['weight']?></td>
            </tr>
            <tr>
               <td class="medium">已设线上笔试</td>
               <td><?=$summary['details']['onlinetest_setup']['count']?></td>
               <td><?=$summary['details']['onlinetest_setup']['weight']?></td>
            </tr>
            <tr>
               <td class="medium">已设性格评测</td>
               <td><?=$summary['details']['persontest_setup']['count']?></td>
               <td><?=$summary['details']['persontest_setup']['weight']?></td>
            </tr>
         </table>
      </div>
   </div>
</div>

<div class="rep_resumefrom" id="anchor_from">
   <h5><b>来源情况</b></h5>

   <div class="clearfix">
      <div class="rep_detailtable pull-left" style="width:55%;">
         <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
               <th width="20%">来源</th>
               <th width="40%">职位数</th>
               <th width="40%">比例</th>
            </tr>
            <? if (!empty($summary['source']['total'])):
               $sourceList = array(
                  'pipapai' => array('text' => '枇杷派', 'class' => 'pipapai'),
                  '51job' => array('text' => '前程无忧', 'class' => 'job51'),
                  'zhilian' => array('text' => '智联招聘', 'class' => 'zhilian'),
                  'lagou' => array('text' => '拉勾', 'class' => 'lagou'),
                  'jiancai' => array('text' => '建筑英才', 'class' => 'jiancai')
               );
               $sources = array_keys($summary['source']['total']);
               $sources_sorted = array_keys($sourceList);
               $sources = array_values(array_intersect($sources_sorted, $sources));
               foreach($sources as $s):
                  $t = $summary['source']['total'][$s];
               ?>
               <tr>
                  <td class="tleft"><i class="<?=$sourceList[$s]['class']?>"></i> <?=$sourceList[$s]['text']?></td>
                  <td><?=$t['count']?></td>
                  <td><?=$t['weight']?></td>
               </tr>
               <? endforeach; ?>
            <? else: ?>
               <tr><td colspan="3"><div class="nodatacolor">暂无数据</div></td></tr>
            <? endif; ?>   
         </table>
      </div>

      <div class="pull-right" style="width:45%;">
         <? if (!empty($summary['source']['pie']['data'])): ?>
            <div id="jobSourcePie" style="height:165px; width:165px; margin:auto;"></div>
         <? else: ?>
            <div class="nodatacolor" style="width:210px; margin:auto; text-align: center; padding-top: 20px;">暂无数据</div>
         <? endif; ?>
      </div>
   </div>
</div>

<div class="rep_resumefrom" id="anchor_zhaopin">
   <h5><b>招聘情况</b></h5>
   <div id="jobList" class="rep_detailtable">
      <?php
      $tmpl->printpage();
      ?>
   </div>
</div>


<script type="text/javascript">
$(document).ready(function(){
   var summary = <?=json_encode($summary)?>;
   var charts = new Array();
   $(window).unbind('resize');

   if($('#dateLine').length > 0) {
      charts[charts.length++] = $.jqplot('dateLine',  summary.date.lines.data, {
         seriesColors: ['#d9a300', '#06aaff'],
         axes:{
            xaxis:{
               renderer: $.jqplot.CategoryAxisRenderer,
               ticks: summary.date.lines.ticks
            },
            yaxis:{
               min: 0,
               max: summary.date.lines.max,
               tickInterval : summary.date.lines.tickInterval,
               tickOptions: {formatString: '%d'}
            }
         },
         seriesDefaults: {
            shadow:false,
            lineWidth:1.5,
            markerOptions:{
               shadow:false,
            },
         },
         series:[],
         highlighter: {
            show: true,
            sizeAdjust: 7.5,
            tooltipAxes: 'y',
            tooltipSeparator: ' - ',
            useAxesFormatters: true
         },
         cursor: {
            show: false
         },
         grid: {
            drawGridLines: false,        // wether to draw lines across the grid or not.
            gridLineColor: '#e9e9e9',   // *Color of the grid lines.
            background: '#ffffff',      // CSS color spec for background color of grid.
            borderColor: '#333333',     // CSS color spec for border around grid.
            borderWidth: 0.5,           // pixel width of border around grid.
            shadow: false,               // draw a shadow for grid.
            shadowAngle: 45,            // angle of the shadow.  Clockwise from x axis.
            shadowOffset: 1.5,          // offset from the line of the shadow.
            shadowWidth: 2,             // width of the stroke for the shadow.
            shadowDepth: 2,             // Number of strokes to make when drawing shadow.
            shadowAlpha: 0.07,         // Opacity of the shadow
         },
      });
   }

   if($("#jobSummaryBar").length > 0) {
      // Can specify a custom tick Array.
      // Ticks should match up one for each y value (category) in the series.
      var ticks = ['已设匹配条件', '已设线上笔试', '已设性格评测'];

      charts[charts.length++] = $.jqplot('jobSummaryBar', [summary.bars.data], {
         seriesColors: [ "#71c5f4"],
         // The "seriesDefaults" option is an options object that will
         // be applied to all series in the chart.
         seriesDefaults:{
            renderer:$.jqplot.BarRenderer,
            rendererOptions: {
               fillToZero: true,
               barWidth: 45,
               barMargin: 70
            },
            pointLabels: {show: true},
            shadow:false,
            showLabel:false
         },
         // Custom labels for the series are specified with the "label"
         // option on the series option.  Here a series option object
         // is specified for each series.
         series:[
            {showLabel:false}
         ],
         // Show the legend and put it outside the grid, but inside the
         // plot container, shrinking the grid to accomodate the legend.
         // A value of "outside" would not shrink the grid and allow
         // the legend to overflow the container.
         legend: {
            show: true,
            placement: 'outsideGrid',
         },
         axesDefaults: {
            tickRenderer: $.jqplot.CanvasAxisTickRenderer ,
            tickOptions: {
               fontSize: '13px'
            }
         },
         axes: {
            // Use a category axis on the x axis and use our custom ticks.
            xaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                ticks: ticks
            },
            // Pad the y axis just a little so bars can get close to, but
            // not touch, the grid boundaries.  1.2 is the default padding.
            yaxis: {
               min:0,
               max: summary.bars.max,
               tickInterval : summary.bars.tickInterval,
               tickOptions: {formatString: '%d'}
            }
         },
         grid: {
            shadow: false,               // draw a shadow for grid.
            drawGridLines: false,        // wether to draw lines across the grid or not.
            gridLineColor: '#e9e9e9',   // *Color of the grid lines.
            background: '#ffffff',      // CSS color spec for background color of grid.
            borderColor: '#333333',     // CSS color spec for border around grid.
            borderWidth: 0.5, 
         }
      });
   }

   if($("#jobSourcePie").length > 0) {
      $.jqplot ('jobSourcePie', [summary.source.pie.data], {
         seriesColors: summary.source.pie.colors,
         seriesDefaults: {
            // Make this a pie chart.
            renderer: jQuery.jqplot.PieRenderer,
            rendererOptions: {
               // Put data labels on the pie slices.
               // By default, labels show the percentage of the slice.
               dataLabels: summary.source.pie.labels,
               showDataLabels: true,
               diameter: 118,         // padding between pie and neighboring legend or plot margin.
               sliceMargin: 2,     // gap between slices.
               fill: true,         // render solid (filled) slices.
               shadow: false,
               shadowOffset: 2,    // offset of the shadow from the chart.
               shadowDepth: 5,     // Number of strokes to make when drawing shadow.  Each stroke
                                   // offset by shadowOffset from the last.
               shadowAlpha: 0.07,   // Opacity of the shadow
               dataLabelPositionFactor:1.2,
               dataLabelThreshold:0
               //dataLabelFormatString:'%.1f%',
            }
         },
         // Custom labels for the series are specified with the "label"
         // option on the series option.  Here a series option object
         // is specified for each series.
         series:[
            {showLabel:false,color:'#71c5f4'},
            {showLabel:false,color:'#ffffff'},
            {showLabel:false,color:'#71c5f4'},
            {showLabel:false,color:'#71c5f4'}
         ],
         legend: {
            show:false,
            location: 'e'
         },
         grid: {
            drawGridLines: false,        // wether to draw lines across the grid or not.
            gridLineColor: '#d3d3d3',   // *Color of the grid lines.
            background: '#ffffff',      // CSS color spec for background color of grid.
            borderColor: '#d3d3d3',     // CSS color spec for border around grid.
            borderWidth: 0,           // pixel width of border around grid.
            shadow: false,               // draw a shadow for grid.
         }
      });
   }

   $(window).resize(function(){
      $.each(charts, function(i, c){
         c.replot( { resetAxes: { xaxis: true } } );
      });
   });

});
</script>